<template>
	<view class="aoi">
		<image class="backahe" :style="{'height':windowHeight}" src="../../static/imglq/back.jpg" mode=""></image>
		<view class="upyz">
			<input type="text" v-model="value" placeholder="请输入账号" />
			<input type="password" v-model="password" placeholder="请输入密码" />
			<button type="default" @click="longin">登录</button>
		</view>
	</view>
</template>

<script>
	import {
		ref,
		computed,
		reactive,
		toRefs,
	} from 'vue'
	
import {useStore} from "vuex"
import http from '../../utils/http.js'
    
	export default {
		setup() {
				let {state, commit} = useStore()
		    	let data = reactive({
				a: 1,
				value: '',
				password: '',
				windowHeight: "200px",
				title: 'hello',
				t(){
					uni.showModal({
						title: '提示',
					  	content: '登录失败',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				},
				longin() {
			
					http({
						url: "/login/getuser",
						method: "get",
						data: {
							username: data.value,
							password: data.password,
						},
				
					}).then((res) => {
						console.log(res);
						let userInfo=res.data.data[0].u_jid
						if (res.data.data.length ) {
							
				          	switch (res.data.data[0].u_jid) {
								
			
								case 5: 
							
								 commit("chaobiao/updateUserInfo", {name:userInfo  })
								
								uni.switchTab({
									url: '../admin/admin'
								});	
								
									break;
								case 6:
								 commit("chaobiao/updateUserInfo", {name:userInfo  })
								uni.switchTab({
									url: '../admin/admin'
								});	
						
									break;
								case 7:
								 commit("chaobiao/updateUserInfo", {name:userInfo  })
								uni.switchTab({
									url: '../admin/admin'
								});	
						
									break;
								case 8:
								  commit("chaobiao/updateUserInfo", {name:userInfo  })
								uni.switchTab({
									url: '../admin/admin'
								});	 
					
									break;
								default:
								data.t();
								break;
				
							}
				
							uni.setStorageSync('user', JSON.stringify(res.data.data[0]));
							uni.setStorageSync('token', res.data.token)
						
						} else {
							data.t();
						}
					});
				
				
				}
				
				
				

			});


			return {
				...toRefs(data)
			};
		},
		onLoad() {
			uni.getSystemInfo({
	         success: (res) => {
					this.windowHeight = res.windowHeight + "px";

				}
			})

		},
		methods: {

		}
	}
</script>

<style lang="scss">
	.aoi {
		position: relative;
		padding:450rpx 175rpx;
		box-sizing: border-box;

		.backahe {
			z-index: -1;
			position: absolute;
			top: 0;
			left: 0;
			width: 750rpx;
		}

		.upyz {
			z-index: 1;

			input {

				width: 400rpx;
				height: 100rpx;
				border-radius: 10rpx;
				margin: 20rpx 0;
				border: 1px solid #FFFFFF;
				background: #E6F1F7 !important;
				font-size: 25rpx;
				padding-left: 20rpx;


			}


			button {
				margin-top: 20rpx;
				margin: auto;
				width: 420rpx;
				height: 100rpx;
				line-height: 100rpx;
				font-size: 25rpx;
				color: #FFFFFF;
				background-color: #83B3C9;
			}
		}
	}
</style>
